package com.kede.app.rest;

import com.kede.annotation.Log;
import com.kede.app.domain.RecyAreaPhone;
import com.kede.app.service.RecyAreaPhoneService;
import com.kede.app.service.dto.RecyAreaPhoneQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Pr.li
* @date 2023-07-01
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "recyAreaPhone管理")
@RequestMapping("/api/recyAreaPhone")
public class RecyAreaPhoneController {

    private final RecyAreaPhoneService recyAreaPhoneService;

    /**
     * 导出数据
     **/
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('recyAreaPhone:list')")
    public void exportRecyAreaPhone(HttpServletResponse response, RecyAreaPhoneQueryCriteria criteria) throws IOException {
        recyAreaPhoneService.download(recyAreaPhoneService.queryAll(criteria), response);
    }

    /**
    * 查询recyAreaPhone
    **/
    @GetMapping
    @Log("查询recyAreaPhone")
    @ApiOperation("查询recyAreaPhone")
    @PreAuthorize("@el.check('recyAreaPhone:list')")
    public ResponseEntity<Object> queryRecyAreaPhone(RecyAreaPhoneQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(recyAreaPhoneService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
    * 新增recyAreaPhone
    **/
    @PostMapping
    @Log("新增recyAreaPhone")
    @ApiOperation("新增recyAreaPhone")
    @PreAuthorize("@el.check('recyAreaPhone:add')")
    public ResponseEntity<Object> createRecyAreaPhone(@Validated @RequestBody RecyAreaPhone resources){
        return new ResponseEntity<>(recyAreaPhoneService.create(resources),HttpStatus.CREATED);
    }


    /**
    * 修改recyAreaPhone
    **/
    @PutMapping
    @Log("修改recyAreaPhone")
    @ApiOperation("修改recyAreaPhone")
    @PreAuthorize("@el.check('recyAreaPhone:edit')")
    public ResponseEntity<Object> updateRecyAreaPhone(@Validated @RequestBody RecyAreaPhone resources){
        recyAreaPhoneService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    /**
    * 删除recyAreaPhone
    **/
    @DeleteMapping
    @Log("删除recyAreaPhone")
    @ApiOperation("删除recyAreaPhone")
    @PreAuthorize("@el.check('recyAreaPhone:del')")
    public ResponseEntity<Object> deleteRecyAreaPhone(@RequestBody Integer[] ids) {
        recyAreaPhoneService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}